import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreDiyConfigService extends BaseService<any> {
  private readonly logger = new Logger(CoreDiyConfigService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getBottomList
   * 对应 PHP: CoreDiyConfigService_core::getBottomList()
   * 逻辑类型: undefined - undefined
   */
  async getBottomList(params: any[]) {
    // 基于PHP真实逻辑: getBottomList
    // PHP原文: $list = array_values(array_filter(event('BottomNavigation', $params)));         $app_bottom_nav_config = [];          if (count($list) > 1) {         ...
const list = array_values(array_filter(event('BottomNavigation', params))];
        const app_bottom_nav_config = [];

        if (count(list) > 1) {
            foreach (list as k => &v) {

                // 将系统底部导航放到第一个位置
                if (v[ 'key' ) == 'app') {
                    const app_bottom_nav_config = v;
                    unset(list[ k );
  }
            const list = array_values(list);
  }

  /**
   * getBottomConfig
   * 对应 PHP: CoreDiyConfigService_core::getBottomConfig()
   * 逻辑类型: undefined - undefined
   */
  async getBottomConfig(site_id: number, key: number) {
    // 基于PHP真实逻辑: getBottomConfig
    // PHP原文: $default_config = $this->getBottomList([ 'key' => $key ])[ 0 ] ?? [];         if (empty($default_config)) {             $default_config = $this->getBo...
const default_config = this.getBottomList([ key: key ))[ 0 ] || [];
        if (!default_config)) {
            const default_config = this.getBottomList([ key: 'app' ))[ 0 ] || [];
  }

  /**
   * setBottomConfig
   * 对应 PHP: CoreDiyConfigService_core::setBottomConfig()
   * 逻辑类型: undefined - undefined
   */
  async setBottomConfig(site_id: any[], data: any[], key: any[]) {
    // 基于PHP真实逻辑: setBottomConfig
    // PHP原文: return ( new CoreConfigService() )->setConfig($site_id, ConfigKeyDict::DIY_BOTTOM . '_' . $key, $data);     }      /**      * 设置启动页      * @param int ...
return ( this.coreConfigService ).setConfig(site_id, ConfigKeyDict.DIY_BOTTOM  + '_' . key, data);
    }

    /**
     * 设置启动页
     * @param int site_id
     * @param data
     * @return SysConfig|bool|Model
     */
    async setStartUpPageConfig(int site_id, data)
    {
        return ( this.coreConfigService ).setConfig(site_id, 'START_UP_PAGE_' . strtoupper(data[ 'type' )), data];
    }

    /**
     * 获取启动页配置
     * @param int site_id
     * @param string type
     * @return */
    async getStartUpPageConfig(int site_id, string type)
    {
        const info = ( this.coreConfigService ).getConfig(site_id, 'START_UP_PAGE_' . strtoupper(type))[ 'value' ] || [];
        if (!!info)) {
            info[ 'name' ] = typeof info[ 'name' )) ? info[ 'name' ] : '';
  }

  /**
   * setStartUpPageConfig
   * 对应 PHP: CoreDiyConfigService_core::setStartUpPageConfig()
   * 逻辑类型: undefined - undefined
   */
  async setStartUpPageConfig(site_id: any[], data: any[]) {
    // 基于PHP真实逻辑: setStartUpPageConfig
    // PHP原文: return ( new CoreConfigService() )->setConfig($site_id, 'START_UP_PAGE_' . strtoupper($data[ 'type' ]), $data);     }      /**      * 获取启动页配置      * @...
return ( this.coreConfigService ).setConfig(site_id, 'START_UP_PAGE_' . strtoupper(data[ 'type' )), data];
    }

    /**
     * 获取启动页配置
     * @param int site_id
     * @param string type
     * @return */
    async getStartUpPageConfig(int site_id, string type)
    {
        const info = ( this.coreConfigService ).getConfig(site_id, 'START_UP_PAGE_' . strtoupper(type))[ 'value' ] || [];
        if (!!info)) {
            info[ 'name' ] = typeof info[ 'name' )) ? info[ 'name' ] : '';
  }

  /**
   * getStartUpPageConfig
   * 对应 PHP: CoreDiyConfigService_core::getStartUpPageConfig()
   * 逻辑类型: undefined - undefined
   */
  async getStartUpPageConfig(site_id: number, type: number) {
    // 基于PHP真实逻辑: getStartUpPageConfig
    // PHP原文: $info = ( new CoreConfigService() )->getConfig($site_id, 'START_UP_PAGE_' . strtoupper($type))[ 'value' ] ?? [];         if (!empty($info)) {         ...
const info = ( this.coreConfigService ).getConfig(site_id, 'START_UP_PAGE_' . strtoupper(type))[ 'value' ] || [];
        if (!!info)) {
            info[ 'name' ] = typeof info[ 'name' )) ? info[ 'name' ] : '';
  }
}
